<template>
  <div class="question" v-if="info !== ''">
    <van-dropdown-menu>
      <van-dropdown-item ref="drop">
        <template #title>
          <div class="title">
            <span class="t1">面试宝典</span><span class="t2">{{ city }}</span>
          </div>
        </template>
        <template #default>
          <van-index-bar :index-list="indexList">
            <div v-for="(value, key, index) in info.citys" :key="index">
              <van-index-anchor class="anchor" :index="key">
                {{ key }}
              </van-index-anchor>
              <van-cell
                v-for="(item, index2) in value"
                :key="index2"
                :title="item"
                @click.native="cityClick(item)"
              ></van-cell>
            </div>
          </van-index-bar>
        </template>
      </van-dropdown-item>
    </van-dropdown-menu>
    <!-- 渲染岗位对应数据 -->
    <div class="content">
      <div class="tag-area">
        <van-tag
          @click="currIndex = index"
          class="tag"
          v-for="(item, index) in cityPositions[city]"
          :key="index"
          color="#f7f4f5"
          text-color="#9696a6"
          :class="{ active: currIndex === index }"
          >{{ item.name }}</van-tag
        >
      </div>
    </div>
    <!-- 环形图表 -->
    <div class="middle">
      <div class="top">
        <div class="middle-item">
          <div class="item-top">
            <i class="iconfont">&#xe64f;</i>
          </div>
          <div class="item-bottom">常错题库</div>
        </div>
        <div class="middle-item">
          <div class="item-top c2">
            <i class="iconfont">&#xe654;</i>
          </div>
          <div class="item-bottom">收藏题库</div>
        </div>
      </div>
      <div class="top mt33">
        <div class="middle-item">
          <div class="item-top c3">
            <i class="iconfont">&#xe648;</i>
          </div>
          <div class="item-bottom">企业题库</div>
        </div>
        <div class="middle-item">
          <div class="item-top c4">
            <i class="iconfont">&#xe655;</i>
          </div>
          <div class="item-bottom">已答题库</div>
        </div>
      </div>
      <van-circle
        class="circle"
        v-model="circleValue"
        :rate="30"
        :speed="10"
        layer-color="none"
        :color="gradientColor"
      >
        <div class="circle-content">
          <div class="t1">顺序刷题</div>
          <div class="t2">
            {{ this.$store.state.userInfo.collectQuestions.length }}/{{
              info.totalCount
            }}
          </div>
        </div>
      </van-circle>
    </div>
    <div class="line"></div>
    <div class="result">
      <div class="result1">累计收录</div>
      <div class="result2">{{ Number(info.totalCount).toLocaleString() }}</div>
    </div>
    <div class="btn">
      <van-button block color="#00b8d4" class="radius" @click="goQuestionInfo"
        >模拟面试</van-button
      >
    </div>
  </div>
</template>

<script>
import { interviewFilters } from '@/api/question'
export default {
  name: 'question',
  data () {
    return {
      city: '全国',
      indexList: [],
      info: '',
      cityPositions: '',
      circleValue: 0,
      currIndex: 0,
      gradientColor: {
        '100%': 'rgba(228,1,55,0.30)',
        '0%': 'rgba(228,1,55,0.70)'
      }
    }
  },
  methods: {
    goInfo () {
      const _type = this.cityPositions[this.city][this.currIndex].id
      this.$router.push(
        '/home/questionInfo?type=' + _type + '&city=' + this.city
      )
    },
    cityClick (str) {
      this.city = str
      this.$refs.drop.toggle(false)
      this.currIndex = 0
    },
    // 点击模拟面试时跳转到题目详情，并带上参数city与岗位id
    goQuestionInfo () {
      this.$router.push({
        path: '/home/questionInfo',
        query: {
          city: this.city,
          id: this.info.cityPositions[this.city][this.currIndex].id
        }
      })
    }
  },
  // 模拟面试筛选条件
  async beforeCreate () {
    const res = await interviewFilters()
    this.info = res.data.data
    // Object.keys(对象) 对象的所有的key转换成的数组
    // Object.values(对象) 对象的所有的value转换成的数组
    // Object.entries(对象) [[key,value],[key,value]]
    this.indexList = Object.keys(res.data.data.citys)
    this.cityPositions = res.data.data.cityPositions
    // window.console.log(res)
  }
}
</script>

<style lang="less" scoped>
.question {
  .title {
    .t1 {
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      text-align: left;
      color: #222;
      line-height: 25px;
      letter-spacing: 0px;
    }
    .t2 {
      font-size: 12px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: center;
      color: #545671;
      line-height: 16px;
    }
  }
  .anchor {
    background-color: #f7f4f5;
  }
  .content {
    padding: 0 @p15;
    .tag-area {
      width: 100%;
      overflow: auto;
      display: flex;
      align-items: center;
      .tag {
        flex: 0 0 auto;
        padding: 5px 8px;
        margin-right: 10px;
      }
      .active {
        background-color: #0084d4 !important;
        color: #fff !important;
      }
    }
  }
  .middle {
    padding: 16px 41px;
    margin-top: 20px;
    background-color: #fff;
    position: relative;
    .top {
      display: flex;
      justify-content: space-between;
      text-align: center;
      .middle-item {
        .item-top {
          width: 44px;
          height: 44px;
          background: linear-gradient(180deg, #ff8080, #ff4949);
          border-radius: 50%;
          line-height: 44px;
          color: #fff;
          .iconfont {
            font-size: 24px;
          }
        }
        .c2 {
          background: linear-gradient(180deg, #ffda05, #ffb302);
        }
        .c3 {
          background: linear-gradient(180deg, #00ddec, #00b8d4);
        }
        .c4 {
          background: linear-gradient(180deg, #3ee5b1, #1dc779);
        }
      }
      .item-bottom {
        margin-top: 10px;
        font-size: 12px;
      }
    }
    .mt33 {
      margin-top: 33px;
    }
    .circle {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 120px;
      height: 120px;
      background-image: url(~@/assets/circle.png);
      background-size: 100%;
      padding: 10px;
      .circle-content {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        background: linear-gradient(180deg, #ff6f92, #e40137);
        color: #fff;
        font-size: 14px;
        .t1 {
          padding-top: 36px;
        }
      }
    }
  }
  .result {
    text-align: center;
    background-color: #fff;
    .result1 {
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      color: #545671;
      line-height: 25px;
      letter-spacing: 0px;
      padding: 21px 0;
    }
    .result2 {
      font-size: 30px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      color: #545671;
      line-height: 42px;
      letter-spacing: 1px;
      padding-bottom: 20px;
    }
  }
  .btn {
    padding: 20px @p15 5px;
    .radius {
      border-radius: 5px;
    }
  }
}
</style>
